# 基类
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class Base():
    # 初始化驱动
    def __init__(self,driver):
        self.driver = driver
    #封装打开网址
    def get_url(self,url):
        self.driver.get(url)
    #封装定位
    def find_element(self,loc):
        try:
            WebDriverWait(self.driver,20,0.5).until(lambda driver: driver.find_element(*loc).is_displayed())
            # WebDriverWait(self.driver,20,0.5).until(EC.presence_of_element_located((self.driver.find_element(*loc))))
            return self.driver.find_element(*loc)
        except Exception as e:
            print(e)
    # 封装send_keys输入操作
    def send_keys(self,loc,text):
        self.find_element(loc).send_keys(text)
    # 封装点击操作
    def click(self,loc):
        self.find_element(loc).click()
    # 鼠标悬浮操作
    def move(self,loc):
        m = self.find_element(loc)
        ActionChains(self.driver).move_to_element(m).perform()
    # 封装键盘Ctrl操作
    def Ctrl_Keys(self,loc,key):
        self.send_keys(loc,(Keys.CONTROL,key))
    # 封装鼠标双击
    def double_click(self,loc):
        ActionChains(self.driver).double_click(self.find_element(loc)).perform()